Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

713
Views
Use @jest-environment jsdom and @jest-environment node both in the same project [Jest-ReactJS]

We are using "Jest with React Testing Library" for unit testing in our project. In the same project we have some cases those needs "@jest-environment jsdom" and some cases needs @jest-environment node. How can we switch this in a Test Case file.

We have below jest.config.js file:

 /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
    module.exports = {
      preset: 'ts-jest',
      testEnvironment: 'node'
    };

I have tried below approach, but it didn't work in my experience.

/**
 * @jest-environment jsdom
 */

test('use jsdom in this test file', () => {
  const element = document.createElement('div');
  expect(element).not.toBeNull();
});

/**
 * @jest-environment node
 */

test('do not use jsdom in this test file', () => {
  console.log(window); // this will fail as node doesn't have a window object
});
almost 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!